import api from "@/util/api";
async function findAll(pageNo = 1, pageSize = 10, params = {}) {
    let resp = await api({
        url: "/goods-api/api/v1/goods",
        method: "get",
        params: {
            pageNo,
            pageSize,
            ...params
        }
    });
    return resp.data || resp;
}

async function deleteById(id) {
    let resp = await api({
        url:"/goods-api/api/v1/goods/deleteById/" + id,
        method: "delete"
    });
    return resp;
}

async function save(item){

    let resp = await api({
        url: "/goods-api/api/v1/goods/add",
        method: "post",
        data: item
    });
    return resp;
}

async function update(item){
    let resp = await api({
        url: "/goods-api/api/v1/goods/update",
        method: "put",
        data: item
    });
    return resp;
}

async function updatePublicStatus(id,publicStatus){
    let resp = await api({
        url: "/item/publicStatus",
        method: "put",
        params: {
            id,
            publicStatus
        }
    });
    return resp;
}

async function updateNewStatus(id,newStatus){
    let resp = await api({
        url: "/item/newStatus",
        method: "put",
        params: {
            id,
            newStatus
        }
    });
    return resp;
}

async function updateRecommandStatus(id,recommandStatus){

    let resp = await api({
        url: "/item/recommandStatus",
        method: "put",
        params: {
            id,
            recommandStatus
        }
    });
    return resp;
}

async function deleteAll(ids){
    let resp = await api({
        url: "/goods-api/api/v1/goods/delete",
        method: "delete",
        params: {
            ids
        },
        paramsSerializer: {
            indexes: null // 确保参数格式为 ids=1&ids=2
        }
    });
    return resp;
}
export {findAll, deleteById, save, update, updatePublicStatus, updateNewStatus, updateRecommandStatus,deleteAll};